#include "apue.h"
#include <fcntl.h>

char buf1[] = "abcdefghij";
char buf2[] = "ABCDEFGHIJ";

int main(int argc, char *argv[])
{
    printf("argc : %d\n", argc);
    int bhole = 0;
    char *filename = NULL;
    if (2 == argc && 0 == strcmp(argv[1], "nohole")) {
        bhole = 0;
        filename = "file.hole";
    } else {
        bhole = 1;
        filename = "file.nohole";
    }
    int fd;
    if ((fd = creat(filename, FILE_MODE)) < 0)
        err_sys("create error");

    if (write(fd, buf1, 10) != 10)
        err_sys("buf1 write error");
    if (bhole) {
        if (lseek(fd, 16384, SEEK_SET) == -1)
            err_sys("lseek error");
    } else {
        for (int i = 0; i < 16374; ++ i) {
            if (write(fd, "0", 1) != 1){
                err_sys("write 0 error");
                break;
            }
        }
    }
    if (write(fd, buf2, 10) != 10)
        err_sys("buf2 write error");
    close(fd);
    exit(0);
}
